package com.example.demo.Controller;

import com.example.demo.Entity.RegisterFunctionCmd;
import com.example.demo.Entity.Result;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.ssssssss.magicapi.provider.MagicAPIService;

import java.util.HashMap;
import java.util.Map;

@Api(tags = "激活某个函数过滤器", description = "其他类型的服务")
@RestController
@Slf4j
@RequestMapping("/activate")
public class ActivateFilterController {
    @Autowired
    MagicAPIService magicAPIService;
    @Autowired
    FunctionMapImpl functionMap;
    @PostMapping("/add")
    @ResponseBody
    public Result<String> activateFunc(@RequestParam(value = "ApiId") String ApiId,
                                       @RequestParam(value = "FuncId") String FuncId,
                                       @RequestParam(value = "preOrPost") Integer preOrPost){
        if (preOrPost==0) {
            functionMap.addPreMap(ApiId, FuncId);
        }else {
            functionMap.addPostMap(ApiId, FuncId);
        }
        return Result.success("OK");
    }
    @PostMapping("/delete")
    @ResponseBody
    public Result<String> deleteFunc(@RequestParam(value = "ApiId") String ApiId,
                                     @RequestParam(value = "preOrPost") Integer preOrPost){
        if (preOrPost==0) {
            functionMap.deletePreMap(ApiId);
        }else {
            functionMap.deletePostMap(ApiId);
        }
        return Result.success("OK");
    }
    @PostMapping("/test")
    @ResponseBody
    public Result<String> deleteFunc(){
        Map<String, Object> params = new HashMap<>();
        params.put("q", "1");
        params.put("s", "2");
        magicAPIService.invoke("/230/234",params);
        return Result.success("OK");
    }
}
